import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * Created by Administrator on 2016/9/21.
 */
public class StringToTime {

    private static String FORMATSTR = "HH:mm";
    public static void main(String[] args) {
            // A string of time information
            //
            String time = "15:30:18";

            DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
            try {
                Date date = sdf.parse(time);
                System.out.println("Date and Time: " + date);
            } catch (Exception e) {
                e.printStackTrace();
            }
    }
    public static Date StringToDate(String dateStr, String formatStr){
        DateFormat sdf=new SimpleDateFormat(formatStr);
        Date date=null;
        try {
            date = sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
